<template>
	<view>
		<scroll-view scroll-y="true" enable-back-to-top class="scroll-box">
			<view class="post-list " v-if="foundList.length">
				<view v-for="(item, index) in foundList" :key="index" @click="postDetail(item.post_id)">
					<view class="post-item">
						<!--用户信息-->
						<view class="post-item-top-user">
							<view>
								<u-avatar class="avatar" :src="item.member_headimg"></u-avatar>
							</view>
							<view class="center">
								<view style="display: felx;align-items: center;">
									<text class="username">{{item.member_name}}</text>
								</view>
							</view>
						</view>
						<!--帖子列表-->
						<view class="post-content">
							<view class="post-text" v-if="item.title">{{item.title}}</view>
							<rich-text class="post-text" :nodes="item.content"></rich-text>
							<!-- 帖子类型 -->
							<view v-if="item.type == 1 || item.type ==0">
								<!--一张图片-->
								<block v-if="item.media.length == 1">
									<image :lazy-load="true" mode="aspectFill" class="img-style-1"
										:src="$util.img(item.media[0])"
										@tap.stop="previewImage(item.media[0], item.media)"></image>
								</block>
								<!--二张图片-->
								<block v-if="item.media.length == 2">
									<view class="img-style-2">
										<image :lazy-load="true" v-for="(mediaItem, index2) in item.media" :key="index2"
											@tap.stop="previewImage(mediaItem, item.media)" mode="aspectFill"
											:src="$util.img(mediaItem)"></image>
									</view>
								</block>
								<!--三张以上图片-->
								<block v-if="item.media.length > 2">
									<view class="img-style-3">
										<image :lazy-load="true" v-for="(mediaItem, index2) in item.media" :key="index2"
											@tap.stop="previewImage(mediaItem, item.media)" mode="aspectFill"
											:src="$util.img(mediaItem)"></image>
									</view>
								</block>
							</view>
							<!-- 视频 -->
							<view class="video-wrap" v-if="item.type == 2 && item.media.length > 0">
								<image class="icon" src="/static/play.png"></image>
								<image mode="aspectFill"
									:src="item.media[0] + '?x-oss-process=video/snapshot,t_0,f_jpg'">
								</image>
							</view>
						</view>

					</view>
				</view>
				<u-loadmore v-if="foundList.length" height="80rpx" :status="loadStatus" icon-type="flower"
					color="#ccc" />
			</view>
		</scroll-view>
	</view>
</template>

<script>
	import Config from '../../common/js/config.js'
	import globalConfig from '@/common/js/golbalConfig.js';
	export default {
		data() {
			return {
				foundList: [],
				lastPage: 1,
				currentPage: 1,
				status: 'loadmore',
				showEmpty: false,
				topicId: ''
			}
		},
		onShow() {
			// 刷新多语言
			this.$langConfig.refresh();
		},
		onLoad(options) {
			if (options.topic_id) {
				this.topicId = options.topic_id;
				this.getCircleIndex();
			} else {
				this.$util.redirectTo('/newpages/social/found', {}, 'redirectTo');
			}
			//登录后查询
			if (uni.getStorageSync('userInfo')) {
				this.member_id = uni.getStorageSync('userInfo').member_id
			}
		},
		onReachBottom() {

		},
		mixins: [globalConfig],
		methods: {

			//圈子列表
			getCircleIndex() {
				this.loadStatus = 'loading';
				this.$api.sendRequest({
					url: '/social/api/topic/totopic',
					data: {
						page: this.currentPage,
						topic_id: this.topicId
					},
					success: res => {
						if (res.code == 0) {
							this.foundList = [...this.foundList, ...res.data.data];
							this.isEmpty = !this.foundList.length;
							this.lastPage = res.data.last_page;
							this.loadStatus = this.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
						}
					},
					fail: res => {
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				});
			},
			postDetail(postId) {
				this.$util.redirectTo('/newpages/social/detail', {
					post_id: postId
				});
			},

		}
	}
</script>

<style lang="scss" scoped>
	.scroll-box {
		height: 100vh !important;
		white-space: nowrap;
	}

	.post-item {
		background: #fff;
		padding: 20rpx;
		margin-bottom: 20rpx;

		.post-content {
			margin-top: 20rpx;

			.img-style-1 {
				display: block;
				width: 75%;
				max-height: 326rpx;
				border-radius: 5px;
				overflow: hidden;
			}

			.img-style-2 {
				display: flex;

				image {
					margin: 5rpx;
					border-radius: 5px;
					width: 100%;
					height: 294rpx;
				}
			}

			.img-style-3 {
				display: flex;
				flex-wrap: wrap;

				image {
					width: 31.3%;
					height: 200rpx;
					margin: 1%;
					border-radius: 5px;
				}
			}
		}

	}

	.post-item-top-user {
		display: flex;
		align-items: center;

		.avatar {
			width: 85rpx;
			height: 85rpx;
			border-radius: 50%;
			margin-right: 20rpx;
		}

		.center {
			flex: 1;
			display: flex;
			flex-direction: column;
			font-size: 24rpx;
			color: #999;

			.username {
				font-size: 32rpx;
				font-weight: 600;
				color: #616161;
			}


		}

	}
</style>
